<?php

/**
  彩票信息模块 
 */

namespace McWin\Controller;
use Common\Controller\HomebaseController;
// load("@.myfunc");

class LottoController extends HomebaseController {

	function _initialize(){}


	/**
	 *  读取赔率数据.
	 *	nmg_k3: 内蒙古快3
	 *  bj_cars: 北京赛车
	 *
	 */	
	

	/**
	 * 读取彩种的赔率和投注上限。
	 * @return [type]: 彩种
	 */
	public function getOdds(){
		$type = $_POST['type'];
		
		if ( $type == '' ){			
			$this->return_data_error('-2');
			return;
		}
		
		// 内蒙古 快3
		if($type === 'nmg_k3'){
			$nmg = A('NmgK3');
			$nmg -> sendOdds();
		}else if($type === 'bj_cars'){
			// 北京赛车
			$bj = A('BjCars');
			$bj -> sendOdds();
		}
		
	}

	/**
	 * 读取开奖数据.
	 * @return [type]
	 */
	public function readOpen(){		
		$type = $_POST['type'];

		if ( $type == '' ){			
			$this->return_data_error('-2');
			return;
		}

		// 内蒙古 快3
		if($type === 'nmg_k3'){
			$nmg = A('NmgK3');
			$nmg -> sendOpen();		
		}else if($type === 'bj_cars'){
			// 北京赛车
			$bj = A('BjCars');
			$bj -> sendOpen();		
		}
	}


	/**
	 * 读未结注单
	 * @return [type] [description]
	 */
	public function readBetsUnfinished(){
		$userID = $_POST['userID'];

		if ( $userID == '' ){			
			$this->return_data_error('-2');
			return;
		}

		$d_bets = D('CccBet');
		$data['userID'] = $userID;
		$data['list'] = $d_bets -> read_bets_unfinished_of_user($userID);

		$this -> return_data($data);
	}


	/**
	 * 读历史注单
	 * 默认读一个
	 * @return [type] [description]
	 */
	public function readBetsHis(){
		$userID = $_POST['userID'];
		$week = $_POST['week'];

		if ( $userID == '' ){			
			$this->return_data_error('-2');
			return;
		}
		
		if($week == '' || $week == null )
		{
			$week = 1;
		}
		if( $week != '1' ){
			$week = 2;
		}

		$weekDays = $week * 7 - 1;

		$d_bets = D('CccBet');
		$data['userID'] = $userID;
		$data['week'] = $week;
		$data['weekDays'] = $weekDays;
		$arr = $d_bets -> read_bets_his_of_user($userID, $weekDays);

		// ----------------------- 汇总 -------------------------------------------------------
		$data['touZhu']	= double_format($arr['touZhu']==null?0:array_sum($arr['touZhu']));
		$data['win']	=	double_format($arr['win']==null?0:array_sum($arr['win']));
		$data['lost']	=	double_format($arr['lost']==null?0:array_sum($arr['lost']));
		$data['cancel']	=	double_format($arr['cancel']==null?0:array_sum($arr['cancel']));

		$data['list'] = $arr;
		
		$this -> return_data($data);
		
	}

	/**
	 * 读某一天的历史详细记录
	 * @return [type] [description]
	 */
	public function readBetsOfDay(){
		$userID = $_POST['userID'];
		$day = $_POST['day'];

		if ( $userID == '' ){			
			$this->return_data_error('-2');
			return;
		}

		if($day == '')
			$day = date('Y-m-d');
		
		$d_bets = D('CccBet');
		$data['userID'] = $userID;
		$data['day'] = $day;
		$data['list'] = $d_bets -> read_bets_xx_of_user($userID, $day);

		$this -> return_data($data);
		
	}
	
}